package com.qlhx.timer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Create by byl
 *
 * @versio 1.0.0
 * @Author baiyanlong
 * @date 2019/7/23 16:34
 * @description desc:
 */
@Component
@EnableScheduling
@PropertySource("classpath:application-configs.properties")
public class TimerTaskSycn {

    Logger logger = LoggerFactory.getLogger(TimerTaskSycn.class);
    @Value("${companycode}")
    public String companycode;// 公司标识编码
    @Value("${isopensenddata}")  //数据上传的开关
    private boolean  isOpenSendData;
    // 数据上传url
    @Value("${data.upload.url}")
    private String dataUploadUrl ;
    @Scheduled(cron = "${datatoplatformDataTime}")
    private void sendData() {
        if (isOpenSendData) {
            logger.info("开始执行数据同步任务！");
            try {
                new SycDateUtil().syncData(dataUploadUrl,companycode);
            } catch (Exception e) {
                e.printStackTrace();
            }
            logger.info("同步任务执行完成！");
        } else {
            logger.info("没有开启数据同步开关 ！");
        }
    }
}
